﻿using BaseUI;
using BLL;
using System;
using System.Data;
using System.Linq;
using Thksoft.Module.DataDetail;

namespace Thksoft.UserCotrols
{
    public partial class PlanDetailOne_Month : BaseControl
    {
        public DataTable dt;

        protected void Page_Load(object sender, EventArgs e)
        {
            BindData();
        }

        //主营业务收入明细表(T1)
        public void BindData()
        {
            var pPage = this.Page as ProjectFundDetail_Month;
            lblyear.Text = pPage.myDate;
            lbldw.Text = pPage.cmyName;
            HiddenField1.Value = pPage.year;
            HiddenField2.Value = pPage.month;
            decimal sum;
            dt = new QS_PLAN_DETAIL1_BLL().GetTable1((int)pPage.planappId);// GetTable(pPage.planappId, 2,out sum);
            sum = dt.AsEnumerable().Sum(a => a["N_AMOUNT"] == DBNull.Value ? 0 : Convert.ToDecimal(a["N_AMOUNT"]));
            var row = dt.NewRow();
            //row["R"] = DBNull.Value;
            row["C_PRONAME"] = "合计";
            row["N_DOSAGE"] = DBNull.Value;
            row["N_PRICE"] = DBNull.Value;
            row["N_WEEK_AMOUNT"] = dt.AsEnumerable().Sum(a => (a["N_WEEK_AMOUNT"] == DBNull.Value ? 0 : Convert.ToDecimal(a["N_WEEK_AMOUNT"])));
            row["N_WEEK_USEAMOUNT"] = dt.AsEnumerable().Sum(a => (a["N_WEEK_USEAMOUNT"] == DBNull.Value ? 0 : Convert.ToDecimal(a["N_WEEK_USEAMOUNT"])));
            row["N_AMOUNT"] = sum;
            row["N_USEAMOUNT"] = dt.AsEnumerable().Sum(a => (a["N_USEAMOUNT"] == DBNull.Value ? 0 : Convert.ToDecimal(a["N_USEAMOUNT"])));
            //row["C_BANK"] = DBNull.Value;
            row["C_REMARK"] = DBNull.Value;
            dt.Rows.Add(row);

            ViewState["database"] = dt;
            grvShow1.DataSource = dt;
            grvShow1.DataBind();
        }

        /// <summary>
        /// 导出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnDaochu_Click()
        {
            //var dt = (DataTable)ViewState["database"];
            //dt.Columns["N_NUM"].ColumnName = "序号";
            //dt.Columns["C_PRONAME"].ColumnName = "项目名称";
            //dt.Columns["N_DOSAGE"].ColumnName = "销售量";
            //dt.Columns["N_PRICE"].ColumnName = "单价";
            //dt.Columns["N_AMOUNT"].ColumnName = "金额";
            //dt.Columns["C_BANK"].ColumnName = "银行现金流向";
            //dt.Columns["C_REMARK"].ColumnName = "备注";
            //dt.Columns.Remove("N_ID1");
            //dt.Columns.Remove("N_PRO_ID");
            //dt.Columns.Remove("N_TYPE");
            //dt.Columns.Remove("N_PLANAPP_ID");
            //dt.Columns.Remove("PRONAME");

            var execll = new BasePage();
            //execll.toExecl1(dt, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "主营业务收入周明细表");
            execll.toExecl1(Panel1, "主营业务收入月明细表" + DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Millisecond.ToString());
        }

        /// <summary>
        /// 打印
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnPrint_Click()
        {
            var key = Guid.NewGuid().ToString();
            Session[key] = FORM_PRINT_VALUE.Value;
            MessageBox.ResponseScript(Page, "top.MessageBox.Print({Value:\"ID=HTML&VALUE=" + key + "\",Area:[\"800px\",\"500px\"],Scrollbar:true})");
        }
    }
}